package com.zhoux.controller;

import com.zhoux.pojo.User;
import com.zhoux.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: taoyi
 * @date: 2021/5/31 11:00
 * @version: 1.0
 * @explain:
 */
@RestController // 将返回值转换为json数据
@RequestMapping("/user")
@CrossOrigin // 跨域请求
public class UserController {
    @Autowired(required = false)
    private UserServiceImpl userServiceImpl;
    @RequestMapping("/get")
    List<User> getAll(){
        return userServiceImpl.getAll();
    }

    @RequestMapping("/addUser")
    public String  addUser(User user){
        userServiceImpl.addUser(user);
        System.out.println("新增成功~~~");
        return "新增成功~~~";
    }

    @RequestMapping("/getUserById")
    User getUserById(Integer id){
        return userServiceImpl.getUserById(id);
    }

}
